{template 'common/header'}
<script type='text/javascript' src='resource/js/lib/jquery-1.11.1.min.js'></script>
<script type="text/javascript" src="../addons/feng_auction/template/js/jquery.gcjs.js"></script>
<script type="text/javascript" src="../addons/feng_auction/template/js/jquery.form.js"></script>
<script type="text/javascript" src="../addons/feng_auction/template/js/tooltipbox.js"></script>
<style type="text/css">
.red {float:left;color:red}
.white{float:left;color:#fff}
.tooltipbox {
	background:#fef8dd;border:1px solid #c40808; position:absolute; left:0;top:0; text-align:center;height:20px;
	color:#c40808;padding:2px 5px 1px 5px; border-radius:3px;z-index:1000;
}
.red { float:left;color:red}
</style>
<ul class="nav nav-tabs">
	<li><a href="{php echo $this->createWebUrl('goods', array('op'=>'display'));}">商品列表</a></li>
	<li {if empty($id)}class="active"{/if}><a href="{php echo $this->createWebUrl('goods', array('op'=>'edit'));}">添加商品</a></li>
	{if !empty($id)}
	<li class="active"><a href="{php echo $this->createWebUrl('goods', array('op'=>'edit', 'id'=>$id));}">编辑商品</a></li>
	{/if}
</ul>

<div class="main">
	<form action="" method="post" class="form-horizontal form" id="form">
		<div class="panel panel-default">
			<div class="panel-heading">拍卖商品</div>
			<div class="panel-body">
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">商品标题</label>
					<div class="col-xs-12 col-sm-8">
						<input type="text" name="goods[title]" class="form-control" value="{$goods['title']}" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">拍卖时间</label>
					<div class="col-sm-4 col-xs-6">{php echo tpl_form_field_date('goods[start_time]', !empty($goods['start_time']) ? date('Y-m-d H:i',$goods['start_time']) : date('Y-m-d H:i'), 1)}</div>
					<div class="col-sm-4 col-xs-6">{php echo tpl_form_field_date('goods[end_time]', !empty($goods['end_time']) ? date('Y-m-d H:i',$goods['end_time']) : date('Y-m-d H:i'), 1)}</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">商品图片</label>
					<div class="col-xs-12 col-sm-8">
						{php echo tpl_form_field_image('goods[picarr]', $goods['picarr']);}
					</div>
					<span class="help-block">图片建议为180*180</span>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">起拍价格</label>
					<div class="col-xs-12 col-sm-8">
						<div class="input-group">
							<input type="text" name="goods[sh_price]" class="form-control" value="{$goods['sh_price']}" {if !empty($goods['start_time'])}{if time()>$goods['start_time']}readonly="readonly"{/if}{/if}>
							<span class="input-group-addon">元</span>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">加价幅度</label>
					<div class="col-xs-12 col-sm-8">
						<div class="input-group">
							<input type="text" name="goods[add_price]" class="form-control" value="{$goods['add_price']}" {if !empty($goods['start_time'])}{if time()>$goods['start_time']}readonly="readonly"{/if}{/if}>
							<span class="input-group-addon">元</span>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">保证金</label>
					<div class="col-xs-12 col-sm-8">
						<div class="input-group">
							<input type="text" name="goods[bond]" class="form-control" value="{$goods['bond']}" {if !empty($goods['start_time'])}{if time()>$goods['start_time']}readonly="readonly"{/if}{/if}>
							<span class="input-group-addon">元</span>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">商品详情</label>
					<div class="col-sm-9 col-xs-12">
						<textarea name="goods[content]" class="form-control richtext" cols="70">{$goods['content']}</textarea>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">状态</label>
					<div class="col-xs-12 col-sm-8">
						<label class="radio radio-inline">
							<input type="radio" name="goods[g_status]" value="1" {if intval($goods['g_status']) != 2}checked="checked"{/if}> 下架
						</label>
						<label class="radio radio-inline">
							<input type="radio" name="goods[g_status]" value="2" {if intval($goods['g_status']) == 2}checked="checked"{/if}> 上架
						</label>
					</div>
				</div>
				{if !empty($id)}
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">添加日期</label>
					<div class="col-xs-12 col-sm-8">
						<p class="form-control-static">{php echo date('Y-m-d', $goods['createtime']);}</p>
					</div>
				</div>
				{/if}
				<div class="form-group">
					<div class="col-xs-12 col-sm-9 col-md-10 col-lg-10 col-sm-offset-3 col-md-offset-2 col-lg-offset-2">
						<input type="hidden" name="id" value="{$goods['id']}" />
						<input name="submit" type="submit" value="提交" class="btn btn-primary" />
						<input type="hidden" name="token" value="{$_W['token']}" />
					</div>
				</div>
			</div>
		</div>
	</form>
</div>

<script>
require(['jquery', 'util'], function($, util){
	$(function(){
		$('#form').submit(function(){
			if($('input[name="goods[title]"]').val() == ''){
				util.message('请填写拍品名称.');
				return false;
			}
			if($('input[name="goods[picarr]"]').val() == ''){
				util.message('请上传拍品图片.');
				return false;
			}
			var add_price = parseFloat($('input[name="goods[add_price]"]').val());
			if(isNaN(add_price)){
				util.message('请填写拍品默认加价价格.');
				return false;
			}
			var sh_price = parseFloat($('input[name="goods[sh_price]"]').val());
			if(isNaN(sh_price)){
				util.message('请填写商品起拍价格.');
				return false;
			}
			return true;
		});
	});
});
require(['jquery', 'util'], function($, u){
	$(function(){
		u.editor($('.richtext')[0]);
	});
});
</script>
{template 'common/footer'}